package test.serverframe.armc.server.manager.dao.mapper;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import test.serverframe.armc.server.manager.domain.LinkInterface;
import test.serverframe.armc.server.manager.domain.LinkParam;

public interface LinkParamMapper {
    @Delete({
            "delete from tb_ssgp_link_param",
            "where link_param_id = #{linkParamId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String linkParamId);

    @Insert({
            "insert into tb_ssgp_link_param (link_param_id, inter_relate_task_id, in_header, in_body, in_query, out_value, exception_sign)",
            "values (",
            "#{linkParamId,jdbcType=VARCHAR},",
            "#{interRelateTaskId,jdbcType=VARCHAR}, ",
            "#{inHeader,jdbcType=VARCHAR},",
            "#{inBody,jdbcType=VARCHAR},",
            "#{inQuery,jdbcType=VARCHAR} ",
            "#{outValue,jdbcType=VARCHAR}",
            "#{exceptionSign,jdbcType=INTEGER}",
            ")"
    })
    int insert(LinkParam record);

    @InsertProvider(type = LinkParamSqlProvider.class, method = "insertSelective")
    int insertSelective(LinkParam record);

    @Select({
            "select",
            "link_param_id, inter_relate_task_id, in_header, in_body, in_query, out_value, exception_sign",
            "from tb_ssgp_link_param",
            "where link_param_id = #{linkParamId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "link_param_id", property = "linkParamId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "inter_relate_task_id", property = "interRelateTaskId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_header", property = "inHeader", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_body", property = "inBody", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_query", property = "inQuery", jdbcType = JdbcType.VARCHAR),
            @Result(column = "out_value", property = "outValue", jdbcType = JdbcType.VARCHAR),
            @Result(column = "exception_sign", property = "exceptionSign", jdbcType = JdbcType.VARCHAR)
    })
    LinkParam selectByPrimaryKey(String linkParamId);

    @UpdateProvider(type = LinkParamSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LinkParam record);

    @Update({
            "update tb_ssgp_link_param",
            "set inter_relate_task_id = #{interRelateTaskId,jdbcType=VARCHAR},",
            "in_header = #{inHeader,jdbcType=VARCHAR},",
            "in_body = #{inBody,jdbcType=VARCHAR},",
            "in_query = #{inQuery,jdbcType=VARCHAR}",
            "out_value = #{outValue,jdbcType=VARCHAR}",
            "exception_sign = #{exceptionSign,jdbcType=VARCHAR}",
            "where link_param_id = #{linkParamId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(LinkParam record);

    @Select({
            "select",
            "link_param_id, inter_relate_task_id, in_header, in_body, in_query, out_value, exception_sign",
            "from tb_ssgp_link_param",
            "where inter_relate_task_id = #{interRelateTaskId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "link_param_id", property = "linkParamId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "inter_relate_task_id", property = "interRelateTaskId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_header", property = "inHeader", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_body", property = "inBody", jdbcType = JdbcType.VARCHAR),
            @Result(column = "in_query", property = "inQuery", jdbcType = JdbcType.VARCHAR),
            @Result(column = "out_value", property = "outValue", jdbcType = JdbcType.VARCHAR),
            @Result(column = "exception_sign", property = "exceptionSign", jdbcType = JdbcType.VARCHAR)
    })
    LinkParam selectByInterRelateTaskId(String interRelateTaskId);
    
    @Select({
    	"SELECT lp.link_param_id,lp.inter_relate_task_id,lp.in_header,lp.in_body,",
    			"lp.in_query,lp.out_value,lp.exception_sign",
    	"FROM tb_ssgp_link_param AS lp",
    	"WHERE lp.inter_relate_task_id IN (",
			"SELECT tei.inter_relate_task_id",
			"FROM tb_ssgp_task_enter_interface AS tei",
			"WHERE tei.task_id = #{taskId,jdbcType=VARCHAR}",
		")"
    })
    @Results({
        @Result(column = "link_param_id", property = "linkParamId", jdbcType = JdbcType.VARCHAR, id = true),
        @Result(column = "inter_relate_task_id", property = "interRelateTaskId", jdbcType = JdbcType.VARCHAR),
        @Result(column = "in_header", property = "inHeader", jdbcType = JdbcType.VARCHAR),
        @Result(column = "in_body", property = "inBody", jdbcType = JdbcType.VARCHAR),
        @Result(column = "in_query", property = "inQuery", jdbcType = JdbcType.VARCHAR),
        @Result(column = "out_value", property = "outValue", jdbcType = JdbcType.VARCHAR),
        @Result(column = "exception_sign", property = "exceptionSign", jdbcType = JdbcType.VARCHAR)
    })
    List<LinkParam> selectParamByTaskId(String taskId);
    
    @Select({
    	"SELECT out_value ",
    	"FROM tb_ssgp_link_param",
    	"WHERE inter_relate_task_id = (",
	    	"SELECT parent_id",
	    	"FROM tb_ssgp_link_interface",
	    	"WHERE inter_relate_task_id = #{interRelateTaskId,jdbcType=VARCHAR}",
    	")"
    })
    String selectParentByNodeId(String interRelateTaskId);

    @Delete({
    	"delete from tb_ssgp_link_param",
        "where inter_relate_task_id = #{interRelateTaskId,jdbcType=VARCHAR}"
    })
	void deleteByNodeId(String interRelateTaskId);
    
}
